﻿using DapperCore.Model;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

namespace DapperCore.Startup
{
  public  interface ICoreServices<T>
    {

        /// <summary>
        /// where 条件查询
        /// </summary>
        /// <param name="predicate"></param>
        Option<T> Where(Expression<Func<T, bool>> predicate, bool IsDelete = false);

        /// <summary>
        /// 正序
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="field"></param>
        Order<T> OrderBy<TProperty>(Expression<Func<T, TProperty>> field);

        /// <summary>
        /// 倒叙
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="field"></param>
        Order<T> OrderByDesc<TProperty>(Expression<Func<T, TProperty>> field);

        /// <summary>
        /// 跳过 多少条
        /// </summary>
        /// <param name="SkipsNum"></param>
        /// <returns></returns>
        Skips<T> Skip(int SkipsNum);

        /// <summary>
        /// 显示多少条
        /// </summary>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        Takes<T> Take(int PageSize);


        #region 查询

        /// <summary>
        /// ToListT 包含分页
        /// </summary>
        /// <returns></returns>
        ListT<T> ToList();

        /// <summary>
        /// ToListT 包含分页
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <returns></returns>
        ListT<T1> ToList<T1>();

        /// <summary>
        /// ToList 不包含分页，返回Object
        /// </summary>
        /// <typeparam name="T2"></typeparam>
        /// <returns></returns>
        List<T2> ToListObject<T2>();
        
            /// <summary>
            /// 找到第一条数据
            /// </summary>
            /// <returns></returns>
            T FirstOrDefault();

        /// <summary>
        /// 加上条件过滤 找到第一条数据
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        T FirstOrDefault(Expression<Func<T, bool>> predicate, bool IsDelete = false);

        #endregion

        #region 更新
        /// <summary>
        /// 单条数据更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        int Update(T model);

        /// <summary>
        /// 单条数据更新 Selector
        /// </summary>
        /// <param name="selector"></param>
        /// <returns></returns>
        int Update(Expression<Func<T, T>> selector);

        #endregion


        #region 添加
        /// <summary>
        /// 添加单条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        int Add(T model);

        #endregion


        #region 删除

        /// <summary>
        /// 删除单挑数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        int Delete(T model);

        /// <summary>
        /// 删除单挑数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        int Delete(Guid Id);

        /// <summary>
        /// 永久删除单条数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        int Remove(Guid Id);

        /// <summary>
        /// 永久删除单条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        int Remove(T model);

        #endregion

        #region 执行命令

        /// <summary>
        ///执行命令 
        /// </summary>
        /// <returns></returns>
        bool SaveChange();

        /// <summary>
        /// 执行一条命令
        /// </summary>
        /// <param name="randomNum"></param>
        /// <returns></returns>
        bool SaveChange(int randomNum);

        #endregion

    }
}
